<template>
  <div class="menu">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <el-button @click="$router.push({ name: 'menu-create' })"
          >添加菜单</el-button>
      </div>
      <el-table border :data="tableData" style="width: 100%">
        <el-table-column
          label="编号"
          type="index">
        </el-table-column>
        <el-table-column
          prop="name"
          label="菜单名称">
        </el-table-column>
        <el-table-column
          prop="level"
          label="菜单级数">
        </el-table-column>
        <el-table-column
          prop="icon"
          label="前端图标">
        </el-table-column>
        <el-table-column
          prop="orderNum"
          label="排序">
        </el-table-column>
        <el-table-column
          label="操作">
          <template slot-scope="scope">
            <el-button size="mini" @click="handleEdit(scope.row)">编辑</el-button>
            <el-button size="mini" @click="handleDeletet(scope.row)" type="warning">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
import { getAllMenu, getMenuDelete } from '@/services/menu'
export default {
  name: 'Menu',
  data () {
    return {
      tableData: []
    }
  },
  created () {
    this.loadAllMenu()
  },
  methods: {
    handleEdit (rowData) {
      this.$router.push({
        name: 'menu-update',
        params: {
          id: rowData.id
        }
      })
    },
    handleDeletet (rowData) {
      // 删除的确认提示
      this.$confirm('此操作将永久删除, 是否继续?', '提示')
        .then(async () => {
          const { data } = await getMenuDelete(rowData.id)
          if (data.code === '000000') {
            this.$message.success('删除成功!')
            this.loadAllMenu()
          }
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    async loadAllMenu () {
      const { data } = await getAllMenu()
      if (data.code === '000000') {
        this.tableData = data.data
      }
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
